package com.IT.servletJsp.log;

import com.IT.entity.Log;
import com.IT.service.AdminFunctionService;
import com.IT.service.Impl.AdminFunctionServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(value = "/queryLogJsp")
public class queryLogJsp extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset = utf-8");

        PrintWriter out = response.getWriter();

        AdminFunctionService adminFunctionService = new AdminFunctionServiceImpl();
        List<Log> logList = adminFunctionService.queryLog();

        int id = 0;
        for(Log log : logList){
            out.print("id:"+id+"&emsp;");
            out.print("账号："+log.getAccount()+"&emsp;");
            out.print("姓名："+log.getRealName()+"&emsp;");
            if(log.getAuthority() == 1) {
                out.print("类别：用户&emsp;");
            }
            else if(log.getAuthority() == 2){
                out.print("类别：医生&emsp;");
            }
            else {
                out.print("类别：管理员&emsp;");
            }
            out.print("信息："+log.getContent()+"&emsp;");
            out.print("ip:"+log.getIp()+"&emsp;");
            out.print("登录时间："+log.getLoginTime()+"<br/>");
            id++;
        }
    }
}
